<!DOCTYPE html>
<html>
<head lang="zh-cmn-Hans">
    <meta charset="UTF-8">
    <title>DSBridge Test</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=0.5,user-scalable=no"/>
    <script src="{{ url_for('static',filename='js/jsapi/PartyBuildApi.js') }}"></script>

</head>
<style>
    .btn2 {
        text-align: center;
        background: #d8d8d8;
        color: #222;
        padding: 20px;
        margin: 30px;
        font-size: 24px;
        border-radius: 4px;
        box-shadow: 4px 2px 10px #999;
    }

    .btn:active {
        opacity: .7;
        box-shadow: 4px 2px 10px #555;
    }

    .btn {
        text-align: center;
        background: #d8d8d8;
        color: #222;
        padding: 5px;
        margin: 5px;
        font-size: 24px;
        border-radius: 4px;
        box-shadow: 4px 2px 10px #999;
    }


</style>
<body>
<div>

    <input class="btn" onclick="is_app()" type="button" value="是否APP环境">
    <input class="btn" type="button" onclick="get_token()" value="获取Token">
    <input class="btn" type="button" onclick="hide_title()" value="隐藏标题栏">
    <input class="btn" type="button" onclick="show_title()" value="显示标题栏">
    <input class="btn" type="button" onclick="open_url()" value="打开新页面">
    <input class="btn" type="button" onclick="colse_and_open_url()" value="关闭本页面并打开新页面">
    <input class="btn" type="button" onclick="webview_page_collection()" value="页面收藏">
    <input class="btn" onclick="select_image_upload()" type="button" value="选择图片并上传">


    <input class="btn" type="button" onclick="callSyn()" value="同步返值">
    <input class="btn" type="button" onclick="callAsyn()" value="异步返值">
    <input class="btn" type="button" onclick="callNoArgSyn()" value="同步没有入参">
    <input class="btn" type="button" onclick="callNoArgAsyn()" value="异步没有入参">

</div>
<div><input class="btn" type="button" onclick="echoSyn()" value="echo.Syn">
    <input class="btn" type="button" onclick="echoAsyn()" value="echo.Asyn">
    <input class="btn" type="button" onclick="callProgress()" value="callProgress">

    <input class="btn" type="button" onclick="hasNativeMethod('xx')" value="hasNativeMethod('xx')">
    <input class="btn" type="button" onclick="callAsyn_()"
           value="Stress test，2K times consecutive asynchronous API calls">

</div>

<div class="btn2" onclick="callNever()">Never call because without @JavascriptInterface
    annotation<br/>( This test is
    just for Android ,should be ignored in IOS )
</div>
<div class="btn2" onclick="hasNativeMethod('testSyn')">hasNativeMethod("testSyn")</div>
<div id="callback"></div>
<script>
    function is_app() {
        alert(isApp());
    }

    function get_token() {
        <!--alert(dsBridge.call("getToken", "token"))-->
        alert(getToken())
    }

    function hide_title() {
        hideTitle();
    }

    function show_title() {
        showTitle();
    }

    function colse_and_open_url() {
        closeAndOpenUrl("http://www.baidu.com");

    }

    function open_url() {
        openUrl("http://www.baidu.com");
    }

    function webview_page_collection() {
        alert(setCollection("页面收藏成功"));
    }

    function select_image_upload(str) {
        var str = encodeURI("http://47.93.162.110:8002/cloudtf/file/uploadFile");
        var params = {"url": str};
        selectImageAndUpload(params, imageCallBack)
    }

    function imageCallBack(v) {
        alert(v)
    }


    function callSyn() {
        alert(dsBridge.call("testSyn", "testSyn"))
    }

    function callAsyn() {
        //dsBridge.call("testAsyn","testAsyn11111", function (v) {
        //    alert(v)
        //})
        var str = encodeURI("http://download.appst.cnpc.com.cn:2052/rxfilex/cosupload");
        var params = {"url": str};

        //dsBridge.call("testAsyn",params, callback)
        testAsyn(params, callback2)
    }

    function callback2(v) {
        alert(v)
    }


    function callAsyn_() {
        for (var i = 0; i < 2000; i++) {
            dsBridge.call("testAsyn", "js+" + i, function (v) {
                if (v == "js+1999 [ asyn call]") {
                    alert("All tasks completed!")
                }
            })
        }
    }

    function callNoArgSyn() {
        alert(dsBridge.call("testNoArgSyn"));
    }

    function callNoArgAsyn() {
        dsBridge.call("testNoArgAsyn", function (v) {
            alert(v)
        });
    }

    function callNever() {
        alert(dsBridge.call("testNever", {msg: "testSyn"}))
    }

    function echoSyn() {
        // call function with namespace
        var ret = dsBridge.call("echo.syn", {msg: " I am echoSyn call", tag: 1});
        alert(JSON.stringify(ret))
    }

    function echoAsyn() {
        // call function with namespace
        dsBridge.call("echo.asyn", {msg: " I am echoAsyn call", tag: 2}, function (ret) {
            alert(JSON.stringify(ret));
        })
    }

    function callProgress() {
        dsBridge.call("callProgress", function (value) {
            if (value == 0) value = "";
            document.getElementById("progress").innerText = value
        })
    }

    function hasNativeMethod(name) {
        alert(dsBridge.hasNativeMethod(name))
    }


</script>
</body>
</html>
